package day02.双指针;

public class 盛水最多的容器610 {
    public int maxArea(int[] height) {
        int n = height.length;
        int ret = 0;
        //左右指针
        int left = 0, right = n - 1;
        while (left < right) {
            //先计算面积
            ret = Math.max(ret, Math.min(height[left], height[right]) * (right - left));
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return ret;
    }
    /*public int maxArea(int[] height) {
        int n = height.length;
        int ret = 0;
        // 利用两层for循环
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int chang = j - i;
                int gao = Math.min(height[j], height[i]);
                ret = Math.max(ret, chang * gao);
            }
        }
        return ret;
    }*/
}
